#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMenu>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QIcon icon = QIcon(":/blue.jpg");

    QMenuBar* menubar = this->menuBar();

    QMenu* menu1 = new QMenu("文件 (&a)");
    QMenu* menu2 = new QMenu("选项 (&b)");
    menubar->addMenu(menu1);
    menubar->addMenu(menu2);

    QAction* action1 = new QAction("打开 (&c)");
    action1->setIcon(icon);
    QAction* action2 = new QAction("关闭 (&d)");
    menu1->addAction(action1);
    menu1->addAction(action2);

    this->setMenuBar(menubar);

    connect(action2,&QAction::triggered,this,&MainWindow::close);
}

MainWindow::~MainWindow()
{
    delete ui;
}

